#include <bits/stdc++.h>
#define inf 1000000000000000007LL
#define File(xxx) freopen(xxx".in","r",stdin),freopen(xxx".out","w",stdout)
using namespace std;
typedef long long LL;
const int N = 4e5+5;
int n, cnt, tr[N], vis[N], gs;
LL xx[N], to[N], aa[N], sum[N];
set <int> qq;
struct qwq {
	LL w; int d;
}b[N];

template <typename T> inline void debug(T x) { cerr<<x; }
template <typename T, typename ...T_> inline void debug(T x, T_ ...p) { cerr<<x<<' ', debug(p...); }
template <typename T> void read(T& x) {
	x = 0; int f = 0; char c = getchar();
	while(c < '0' || c > '9') f |= (c == '-'), c=getchar();
	while(c >= '0' && c <= '9') x=(x<<1)+(x<<3)+(c^48), c=getchar();
	x=(f ? -x : x);
}
int lne; char put[105];
template <typename T> void write(T x, char ch) {
	lne = 0; if(x < 0) putchar('-'), x=-x;
	do { put[++lne]=x%10, x/=10; } while(x);
	while(lne) putchar(put[lne--]^48);
	putchar(ch);
}
int comp(qwq A, qwq B) {
	return A.w < B.w;
}
void add(int x, int w) {
	while(x <= cnt)
		tr[x]+=w, x+=(x&(-x));
}
int ask(int x, int ret = 0) {
	while(x)
		ret+=tr[x], x-=(x&(-x));
	return ret;
}
void sol() {
	auto now = qq.begin();
	for(int i = 1; i <= gs; ++i)
		aa[i]=to[(*now)], ++now;
	for(int i = 1; i <= gs; ++i)
		sum[i]=sum[i-1]+aa[i];
	LL ans = 0;
	for(int i = 1; i < gs; ++i)
		ans=ans+sum[gs]-sum[gs-i]-sum[i]-max(0LL, sum[gs]-sum[gs-i+1]-sum[i]);
	write(ans, '\n');
}

signed main() {
	File("kte");
	read(n);
	int pd = 1;
	for(int i = 1; i <= n; ++i)
		read(xx[i]), b[i]=qwq {xx[i], i};
	sort(b+1, b+1+n, comp);
	for(int i = 1; i <= n; ++i) {
		if(i == 1 || b[i].w != b[i-1].w)
			to[++cnt]=b[i].w;
		xx[b[i].d]=cnt;
	}
	for(int i = 1; i <= n; ++i) {
		if(qq.find(xx[i]) != qq.end()) 
			--gs, qq.erase(qq.find(xx[i]));
		else {
			++gs, qq.insert(xx[i]);
		}
		sol();
	}
	return 0;
}
